<?php
namespace Admin\Model;
use Think\Model;

class KeshiModel extends Model {

	protected $tableName = 'hospital_keshi';

	public function index(Array $index) 
	{
		if(!is_array($index)) {
			return false;
		}
		$keshi = $this->join("LEFT JOIN keshi ON hospital_keshi.keshi_id = keshi.id")
					  ->join("LEFT JOIN hospital ON hospital_keshi.hospital_id = hospital.id")
				      ->limit($index["limit"]["firstRow"].','.$index["limit"]["listRows"])
					  ->field('keshi.id,keshi.name as name, hospital.name as hospital_name')
					  ->select();
		return $keshi;
	}
	
	
	public function addkeshi(Array $keshi)
	{
		if(!is_array($keshi)) {
			return false;
		}		
		if (!$this->create($keshi,1)) {
			return false;
		}else{
			return $this->add();
		}
	}
	
	
	public function showkeshi(Array $keshi)
	{
		$keshi = $this->find($keshi["find"]);
		if(empty($keshi)) {
			return false;
		}
		return $keshi;
	}
	
	public function editkeshi(Array $keshi)
	{
		if(!is_array($keshi)) {
			return false;
		}		
		if (!$this->create($keshi,2)) {
			return false;
		}else{
			return $this->save();
		}
	}
	
	public function deletekeshi(Array $keshi)
	{
		if(!is_array($keshi)) {
			return false;
		}		
		if (!$this->create($keshi,2)) {
			return false;
		}else{
			return $this->save();
		}
	}


}